package com.example;

import com.example.fizzbuzz.entity.Dollar;
import com.example.fizzbuzz.entity.Franc;
import com.example.fizzbuzz.entity.Money;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

/**
 * @author duzhou
 * @version 2021/1/23
 */
public class 多币种资金测试 {

    @Test
    public void 测试乘法() {
        Money five = Money.dollar(5);
        assertEquals(Money.dollar(10), five.times(2));
        assertEquals(Money.dollar(15), five.times(3));

        Money franc = Money.franc(5);
        assertEquals(Money.franc(10), franc.times(2));
        assertEquals(Money.franc(15), franc.times(3));

    }

    @Test
    public void testEquality() {
        assertTrue(Money.dollar(5).equals(Money.dollar(5)));
        assertFalse(Money.dollar(5).equals(Money.dollar(6)));
        assertTrue(Money.franc(5).equals(Money.franc(5)));
        assertFalse(Money.franc(5).equals(Money.franc(6)));
        assertFalse(Money.franc(5).equals(Money.dollar(5)));
    }

    @Test
    public void test货币() {
        assertEquals("USD", Money.dollar(1).currency());
        assertEquals("CHF", Money.franc(1).currency());
    }

    @Test
    public void testDifferentClassEquality() {
        assertTrue(new Money(10, "CHF").equals(new Franc(10, "CHF")));
        assertTrue(new Money(10, "CHF").equals(new Dollar(10, "CHF")));
        assertTrue(new Franc(10, "CHF").equals(new Dollar(10, "CHF")));
        assertFalse(new Money(10, "CHF").equals(new Dollar(10, "USD")));
    }
}
